import 'package:shared_preferences/shared_preferences.dart';
import 'package:event_bus/event_bus.dart';
import '../event/ChangeTokenEvent.dart';

EventBus eventBus = EventBus();
class AppConfig {
    static String baseUrl = "http://47.110.198.7:8801/";//正式环境
  // static String baseUrl = "http://116.62.206.127:8001/";//测试环境

  static String appKey = "PRO_091021";
  static String appSecret = "13083748a4e3946580fg45b947f76cbf";

  // static String appKey = "FAT_123456";
  // static String appSecret = "23788ba4988767ew9df1f6ec6f181c30";

  static String guestID = "c50e00db0be52ca5e370b69bd9b24add";
  static String appClient = "iphone";
  static String token =  "0fa22b45bd9ad49fde1d689562eb35ed"; 
  static String channel = "cashloan";
  static String openId = "a32fbd2f-fa3d-4088-8354-de75b4780843";
  static String from = "cashloan";
  static String clientId = "fa999a47fc65bf9d1e112f00b080b943";
  static String appCode = "0000002";

  static Future<String> getToken() async{
    if (token != null && token.length == 0 ) {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      String token = await sharedPreferences.get("token");
      AppConfig.token = token != null ? token : "";
    }
    return token;
  }
  
  static setToken(String token) async {
    if (token != null && token.length > 0) {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      sharedPreferences.setString("token", token);
      AppConfig.token = token;
    }
    else {
      SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
      sharedPreferences.remove("token");
      AppConfig.token = "";
    }
    eventBus.fire(ChangeTokenEvent(token));
  }
  
  static void reLogin() {
    setToken("");
  }
}